package day08.dao;

public class ArrayDao implements UserDao {

	private User[] data;
	private int count;

	public ArrayDao() {
		data = new User[10];
		count = 0;
	}

	public boolean addUser(User u) {
		if (count >= 10) {
			System.out.println("用户已满！");
			return false;
		} else if (count < 10) { // else 后面的条件只能有一个，
			data[count] = u;
			System.out.println("添加用户成功");
			count++;
		}
		return true;
	}

	public User getUser(String userName, String password) {
		if (count == 0) {
			return null;
		}
		for (int i = 0; i < count; i++) {
			if (data[i].getUserName().equals(userName)) {
				if (data[i].getPassword().equals(password)) {

					return data[i];
				}
			}
		}
		return null;
	}
}